/*
 * Dq UI Jquery 
 * 
 */

function getHashFromString(hash) 
{
	
   if (!hash) return false;
   hash = hash.replace(/^.*#/, '');
   if (isNaN(hash)) return hash;
   return false;
}
	        	        
function getHash() 
{
   var hash = location.hash;
   return getHashFromString(hash);
}

/*
 * Select 
 */
(function($) {
	
	$.fn.dqButton = function(settings) 
	{
		// default configuration properties
		var defaults = {			
			type	  :  1,
			clickType : 'href',
			action    : '',
			live	  : true
		}; 
		
		var settings = $.extend(defaults, settings);  
		
		return this.each(function() 
		{
			var obj = $(this);
			
			var btnTxt = obj.html();
			
			if (settings.clickType == 'href')
				btnTxt = '<a href="'+settings.action+'" class="btnType-'+settings.type+'-txt" >'+btnTxt+'</a>';
			else if (settings.clickType == 'js')
			    btnTxt = '<span onclick="'+settings.action+'" class="btnType-'+settings.type+'-txt cpointer">'+btnTxt+'</span>';
			
			obj.addClass('btnType-'+settings.type);
			obj.html('<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td class="btnType-'+settings.type+'-left"></td><td class="btnType-'+settings.type+'-center" align="center">'+btnTxt+'</td><td class="btnType-'+settings.type+'-right"></td></tr></table>');
			
			if (settings.live)
			{
				obj.mouseenter(function()
				{	
					$('.btnType-'+settings.type+'-left',this).addClass('btnType-'+settings.type+'-left-select');
					$('.btnType-'+settings.type+'-center',this).addClass('btnType-'+settings.type+'-center-select');
					$('.btnType-'+settings.type+'-right',this).addClass('btnType-'+settings.type+'-right-select');
				 })
				 .mouseleave(function()
				 {				 
					 $('.btnType-'+settings.type+'-left',this).removeClass('btnType-'+settings.type+'-left-select');
					 $('.btnType-'+settings.type+'-center',this).removeClass('btnType-'+settings.type+'-center-select');
					 $('.btnType-'+settings.type+'-right',this).removeClass('btnType-'+settings.type+'-right-select');
				 });				
			}
		});
	};
	
})(jQuery);

/*
 * Input 
 */
(function($) {
	
	$.fn.dqInput = function(settings) 
	{
		// default configuration properties
		var defaults = {			
			type	  :  1,
			inputType : 'text'
		}; 
		
		var settings = $.extend(defaults, settings);  
		
		return this.each(function() 
		{
			var obj = $(this);
			
			var btnTxt = obj.html();
			
			obj.html('<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td class="inputType-'+settings.type+'-left"></td><td class="inputType-'+settings.type+'-center">'+btnTxt+'</td><td class="inputType-'+settings.type+'-right"></td></tr></table>');			
		});
	};
	
})(jQuery);

/*
 * Img over 
 */
(function($) {
	
	$.fn.dqImgOver = function(settings) 
	{
		// default configuration properties
		var defaults = {over : '', out : ''}; 
		
		var settings = $.extend(defaults, settings);  
		
		return this.each(function() 
		{
			var obj = $(this);
			
			obj.mouseover(function(){ $(this).attr('src',settings.over);  })
			   .mouseout (function(){ $(this).attr('src',settings.out); });						
		});
	};
	
})(jQuery);

/*
 * Dialog 
 */
(function($) {
	
	 var methods = {
		 init : function( settings ) 
		 {
			 var defaults = {
		    				btnClose  : 'btnClose',		    				
		    				isbtnClose: true
		    			}; 
		    			
		    var settings = $.extend(defaults, settings);  
		    			
		    return this.each(function() 
		    {
		    		var obj = $(this);		    				
		    		var btnTxt = obj.html();
		    		var htmlClose = '';
		    		
		    		if (settings.isbtnClose) htmlClose = '<div align="right" id = "btnCloseContainer" class = "btnCloseContainer"><img src="/app/themes/default/images/site/close.png" class="btnClose cpointer" /></div>';
		    		obj.html('<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td width="5" height="5"><img src="/app/themes/default/img/c6_left_top.png" alt="" /></td><td class="c6_bg_top"><img src="/app/themes/default/img/vid.gif" alt="" /></td><td width="5"><img src="/app/themes/default/img/c6_right_top.png" alt="" /></td></tr><tr><td class="c6_bg_left"><img src="/app/themes/default/img/vid.gif" alt="" /></td><td valign="top" class="c6_txt">'+htmlClose+'<div class="tpad10 rpad10">'+btnTxt+'</div></td><td class="c6_bg_right"><img src="/app/themes/default/img/vid.gif" alt="" /></td></tr><tr><td width="5" height="5"><img src="/app/themes/default/img/c6_left_bottom.png" alt="" /></td><td class="c6_bg_bottom"><img src="/app/themes/default/img/vid.gif" alt="" /></td><td width="5"><img src="/app/themes/default/img/c6_right_bottom.png" alt="" /></td></tr></table>   ');
		    				
		    		$('.'+settings.btnClose).click(function(){ obj.fadeOut(); });
		    });
		 },
		 open : function ( settings ) 
		 {	
			 var defaults = { 
					 top   : 100,
					 left  : 0,
					 width : 555
					}; 
	    			
			 var settings = $.extend(defaults, settings);  
	    			
			 return this.each(function() 
			 {				 
				 $(this).fadeIn();
				 var cssObject =  { 
		    		position : 'absolute',
		    		width : settings.width+'px',
		    		right : '0',
		    		left: settings.left+'px',
		    		margin:'0 auto',
		    		top : settings.top+'px'
				 }
				 $(this).css(cssObject);
			 });
		 }
  };

  $.fn.dqDialog = function( method ) 
  {		    
	  if ( methods[method] ) {
		      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
	  } else if ( typeof method === 'object' || ! method ) {
		      return methods.init.apply( this, arguments );
	  } else {
		      $.error( 'Method ' +  method + ' does not exist on jQuery.dqDialog' );
	  }    
		  
   };	
	
})(jQuery);

